//注册vuex
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
//坑1:vuex中的数据页面刷新会重新初始化,所以需要存到本地
//坑2:导出store时要用export default,不要用module.exports
const store = new Vuex.Store({
    state : {
        loading : {
            flag : false
        },
        user : undefined,
        particleGround : undefined
    },
    mutations : {
        setLoading(state,flag){
            state.loading.flag = flag
        },
        setUser(state,user){
            state.user = user
            localStorage.setItem('user',JSON.stringify(user))
        },
        setParticleGround(state,operator){
            state.particleGround = operator
        }
    },
    getters : {
        getLoading(state){
            return state.loading.flag
        },
        getUser(state){
            var user = localStorage.getItem('user')
            if(user != null)
                state.user = JSON.parse(user)
            return state.user
        },
        getParticleGround(state){
            return state.particleGround
        }
    }
})

export default store
